# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=gplugin
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.29.0
pkgrel=5
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
pkgdesc="A GObject based library that implements a reusable plugin system (mingw-w64)"
license=("LGPL 2")
url="https://keep.imfreedom.org/gplugin/gplugin"
depends=("${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-asciidoc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "mercurial"
             "gettext")
options=('strip' '!debug' 'staticlibs')
source=("hg+https://keep.imfreedom.org/$_realname/$_realname#tag=v$pkgver"
        001-win.patch)
sha256sums=('SKIP'
            '97020cd303307dd93d0f84f46542b84d41a32a1d975843e774fe36fb0071008d')

prepare() {
  cd "${srcdir}"/${_realname}
  patch -p1 -i ${srcdir}/001-win.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Dgtk3=true \
    -Dgobject-introspection=true \
    -Dlua=false \
    -Dperl=false \
    -Dpython=false \
    -Dhelp2man=false \
    "../${_realname}"

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ninja install

  install -Dm644 ${srcdir}/${_realname}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
